﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Drawing;
using System.Configuration;
using NuaTarDoneng.Tail;



namespace NuaTarDoneng
{
    /// <summary>
    /// Handler2 的摘要说明
    /// </summary>
    public class imageControl : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string filename = context.Server.MapPath(context.Request.FilePath);
            context.Response.ContentType = ContentTypes.getContenType(filename);
            string url = context.Request.UrlReferrer.Host;
            Logs.InnerLog(context.Server.MapPath("/"), url);
            bool Isok = false;
                if (url.IndexOf("nuatar.com")>=0||url.IndexOf("bishe.org")>=0)
                {
                    Isok = true;
                    Logs.InnerLog(context.Server.MapPath("/"), "合法的地址" + filename);
                }

           
            if (filename.IndexOf("pubkey.txt") >= 0 || filename.IndexOf("Log.txt") >= 0 || filename.IndexOf("innerLog.txt") >= 0)
            {
                Isok = false;
            }
            if (Isok)
            {
                context.Response.WriteFile(filename);

            }
            else
            {
                context.Response.StatusCode = 403;
                context.Response.Redirect("~/403.aspx");
            }
           
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}